/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SStoreConverter.java
 * Created：		2016年7月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.user.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.user.ACompany;
import com.thor.palmmall.spi.user.SCompany;

/**
 * @author Captain
 *
 */
public class ACompanyConverter implements Converter<SCompany, ACompany> {

  public static ACompanyConverter getInstance() {
    if (instance == null)
      instance = new ACompanyConverter();
    return instance;
  }

  private static ACompanyConverter instance;

  private ACompanyConverter() {
  }

  @Override
  public ACompany convert(SCompany source) {
    if (source == null)
      return null;

    ACompany target = new ACompany();
    
    target.setName(source.getName());
    target.setCompanyType(source.getCompanyType());
    
    target.setChannels(ConverterUtil.convert(source.getChannels(), AChannelConverter.getInstance()));
    target.setAccount(source.getAccount());
    target.setSubjects(new ArrayList<UCN>());
    target.getSubjects().addAll(source.getSubjects());
    
    return target;
  }

}
